home *** CD-ROM | disk | FTP | other *** search
- From: "Paul D. DeRocco" <pderocco@ix.netcom.com>
- Message-ID: <31470289.5AFA@ix.netcom.com>
- X-Original-Date: Wed, 13 Mar 1996 12:14:49 -0500
- Path: in2.uu.net!bounce-back
- Date: 13 Mar 96 23:44:55 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: stack variables and new constructor
- Organization: Netcom
- References: <Do7nuy.HsF@ncrcae.ColumbiaSC.ATTGIS.COM>
- X-Netcom-Date: Wed Mar 13 9:16:00 AM PST 1996
- X-Mailer: Mozilla 2.0 (Win95; I)
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMUdeBOEDnX0m9pzZAQEXswF+Kdn3YHowyLnMZomFSqsSYdzPIbthjsgQ
- XDos2AXs67dXisKbA63LY7Pfn1HnHTpJ
- =v5dw
-
- Jon.Cassorla wrote:
- > 1) For a variable that is declared locally to a function of a
- > structure
- > type, is the standard new constructor executed to allocated the
- > memory for the data structure?
-
- No. You mustn't confuse "new" with "constructor". "new" allocates memory
- from the heap (and "delete" returns it). A constructor turns raw memory
- into a valid object (and a destructor turns it back into raw memory).
- Using "new" always calls a constructor if there is one (and "delete"
- always calls a destructor if there is one), but the opposite isn't true.
- If an object is static, it is allocated space by the
- compiler/linker/loader, constructed at the start of the program, and
- destroyed at the end. If an object is dynamic, it is allocated space on
- the stack, constructed when its declaration is executed, and destroyed
- when the containing block exits. Only if it is created in the heap with
- "new" does "operator new" get called.
-
- > 2) When using "new" to allocate data space for a variable of a
- > structure
- > type (ie no constructor defined), is the resulting memory space
- > zero'd
- > out as a standard?
-
- Nope, although there may be OSes that do this.
-
- --
-
- Ciao,
- Paul D. DeRocco
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-